package com.project.dubbo.springboot.consumer.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.project.dubbo.springboot.api.UserServiceClient;
import com.project.dubbo.springboot.api.bo.User;

@RestController
@RequestMapping("/user")
public class UserApi {

	@Reference(
			version = "1.0.0",
			application = "${dubbo.application.id}",
			url = "dubbo://localhost:20880"
	)
	private UserServiceClient userServiceClient;
	
	@RequestMapping("/action/create")
	public boolean createUser(@RequestParam(required = false) User user) {
		return userServiceClient.createUser(user);
	}
	
	@RequestMapping("/{id}")
	public User findById(@PathVariable int id) {
		return userServiceClient.findById(id);
	}
	
	@RequestMapping("/hello/{name}")
	public String sayHello(@PathVariable String name) {
		return "Hello " + name;
	}
}
